#SIFT算法 #FAST算法 #ORB算法
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

img=cv.imread("F:\\11\\19.png")
gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)

def showslow(img):
    plt.figure(figsize=(10,8),dpi=100)
    plt.imshow(img[:,:,::-1]),plt.title('sift')
    plt.xticks([]),plt.yticks([])
    plt.show()
def sift():#SIFT算法
    sift=cv.xfeatures2d.SIFT_create()
    kp,des=sift.detectAndCompute(gray,None)
    cv.drawKeypoints(img,kp,img,flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    return img
def fast():#加入最大值抑制的FAST算法
    fast=cv.FastFeatureDetector_create(threshold=30)#nonmaxSuppression
    kp=fast.detect(img,None)
    img1=cv.drawKeypoints(img,kp,None,color=(0,0,255))
    return img1
def fast1():#没有最大值抑制的FAST算法
    fast=cv.FastFeatureDetector_create(threshold=30)#nonmaxSuppression
    fast.setNonmaxSuppression(0)
    kp=fast.detect(img,None)
    img2=cv.drawKeypoints(img,kp,None,color=(0,0,255))
    return img2
def orb():#orb算法
    orb=cv.ORB_create(nfeatures=500)
    kp,des=orb.detectAndCompute(img,None)
    print(des.shape)
    img3=cv.drawKeypoints(img,kp,None,color=(0,0,255),flags=0)
    return  img3
if __name__=="__main__":
    showslow(fast())
    showslow(fast1())
    showslow(orb())
    showslow(sift())